<template>
  <div style="height: 100%">
    <div class="main-layout">
      <header>
        <div class="title">购宜购旗舰店</div>
        <div class="search">
          <div class="left">
            <img src="../../images/types/icon-13.png" />
            <span>消息</span>
          </div>
          <div class="right">
            <input type="text" random />
          </div>
          <!-- <button @click="classify()">分类</button> -->
        </div>
      </header>
      <main>
        <ul>
          <li>活动精选</li>
          <li>竹纤维专区</li>
          <li>日用百货</li>
          <li>服饰专区</li>
        </ul>
        <van-swipe :autoplay="3000" width="80%" height="210px">
          <van-swipe-item v-for="it in bannerList" :key="it.id">
            <!-- v-lazy是vant组件提供的一个懒加载指令 -->
            <img class="banner-img" v-lazy="it.url" style="width: 100%" />
          </van-swipe-item>
        </van-swipe>

        <!-- 应该是一个二维数组，第一层应该是页数，第二层是每一页的类型数据{icon: 'icon-1', text: '新鲜水果'} -->
        <div class="type">
          <div v-for="(item, index) in typesList" :key="index">
            <img v-lazy="img[index]" />
            <span>{{ typeText[index] }}</span>
          </div>
        </div>
        <!-- 爆款直降 -->
        <div class="hot">
          <span>爆款直降</span>
          <em>当前已抢 3525件</em>
        </div>
        <!-- 热销数据的还原 -->
        <div
          class="recommend-list"
          v-for="item in recommendList"
          :key="item.id"
        >
          <img :src="item.image" width="280px" height="390px" alt="" />
          <div class="title">{{ item.title }}</div>
          <div class="platform"><span>天猫</span> <em>包邮</em></div>
          <div class="price">
            <span>${{ item.price }}</span
            ><span>{{ item.saleNum }}人已买</span>
            <span>{{ item.couponValue }}</span>
          </div>
        </div>

        <!-- <button @click="add">加载更多</button> -->
      </main>
    </div>
    <footer>
      <!-- 因为图片和文字都要变化，所以应该在这个选项上添加一个样式 -->
      <!-- <div
        :class="['item', it.active ? 'active' : '']"
        v-for="it in footerList"
        :key="it.text"
      >
        <i :class="[it.icon]"></i>
        <span>{{ it.text }}</span>
      </div> -->
      <!-- <div>
        <img src="../../images/home.png" alt="" />
        <span>首页</span>
      </div>
      <div>
        <img src="../../images/daipingjia.png" alt="" />

        <span>素材圈</span>
      </div>
      <div>
        <img src="../../images/shoppingcart.png" alt="" />

        <span>购物车</span>
      </div>
      <div>
        <img src="../../images/mine.png" alt="" />

        <span>我的</span>
      </div> -->
      <subscript class="footer"></subscript>

    </footer>
  </div>
</template>

<script>
// 导入模拟服务器
import MockService from "../../apis/homeApi.js";
// // 引入axios
import axios from "axios";
export default {
  data() {
    return {
      arr: [],
      bannerList: [],
      typesList: [],
      recommendList: [],
      footerList: [
        {
          icon: "../../images/home.png",
          text: "首页",
          active: true,
          path: "/home",
        },
        {
          icon: "../../images/daipingjia.png",
          text: "素材圈",
          active: false,
          path: "/type",
        },
        {
          icon: "../../images/shoppingcart.png",
          text: "购物车",
          active: false,
          path: "/video",
        },
        {
          icon: "../../images/mine.png",
          text: "我的",
          active: false,
          path: "/cart",
        },
      ],
      img: [
        require("../../images/types/icon-1.png"),
        require("../../images/types/icon-2.png"),
        require("../../images/types/icon-3.png"),
        require("../../images/types/icon-4.png"),
        require("../../images/types/icon-5.png"),
        require("../../images/types/icon-6.png"),
        require("../../images/types/icon-7.png"),
        require("../../images/types/icon-8.png"),
        require("../../images/types/icon-9.png"),
        require("../../images/types/icon-10.png"),
      ],
      typeText: [
        "新鲜水果",
        "时令蔬菜",
        "肉蛋水产",
        "品牌日",
        "佐餐食材",
        "餐包糕点",
        "粮油调味",
        "乳品冲饮",
        "酒水饮料",
        "休闲零食",
        "居家百货",
        "家纺服饰",
        "个体母婴",
      ],
    };
  },
  methods: {
    classify() {
      this.$router.push("/classify");
    },
  },
  created() {
    axios
      .request({
        url: "https://xiongmaoyouxuan.com/api/detail?id=95371086&normal=1&sa=",
        method: "GET",
        headers: { "x-platform": "pc" },
      })
      .then((data) => {
        this.bannerList = data.data.data.detail.photo;
        // if(data.data.code===200){
        //   this.bannerList = data[0].data.detail.photo.map((it) => {
        //       it.image = "http://www.shuiyue.info:12600" + it.path;
        //       return it;
        //     });
        // }
        // this.getList();
      });
    this.getList();
    let start = this.more() * 20;
    let strMore = [];
    axios
      .request({
        url: "https://xiongmaoyouxuan.com/api/tab/1?start=0" + start,
        method: "GET",
      })
      .then((data) => {
        this.recommendList = data.data.data.baokuanCommodities.list;
        console.log(this.recommendList, "999999999999999999");

        // this.strMore = [...this.recommendLis];
        // this.recommendLis = strMore;
        // console.log(this.recommendLis, "rrrrrrrrrrrrrr");
        // console.log(start, "555555555555555");
      });
  },
  methods: {
    async getUrl() {
      let result = await MockService.getUser();
      debugger;
      if (result.code === 200) {
        this.typesList = result.data.rows;
        this.total = result.data.total;
      }
    },
    getList() {
      this.typesList = this.img.map((item) => {
        return item;
      });
    },
    more() {
      let page = parseInt(Math.random() * 10); //页号

      // page=page=1
      return page;
    },
    add() {
      // more(page)
      console.log(this.more(), "==============");
    },
  },
};
</script>
<style lang="less" scoped>
@import "../../style/common.less";
* {
  margin: 0;
  padding: 0;
}

.main-layout {
  display: block;
  //   height: calc (100%-50px);  这个点就不行
  height: calc(100% - 50px); //减号之间必须要有空格
  background: #dfbfaa;
  > header {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    // height: 100%;
    > .title {
      display: block;
      font-size: 1.1rem;
      color: #fff;
      text-align: center;
      line-height: 24px;
      margin-bottom: 12px;
    }
    > .search {
      display: flex;
      padding: 10px;
      justify-content: space-around;
      > button {
        height: 35px;
      }
      > .left {
        display: block;

        img {
          width: 28px;
          vertical-align: top;
        }
        span {
          display: block;
          display: block;
          font-size: 0.65rem;
          color: #323232;
          // line-height: 24px;
        }
      }
      > .right {
        padding: 10px 0;
        margin-bottom: 16px;
        border-bottom: solid 1px @cdd;
        input {
          flex: 1;
          width: 300px;
          height: 32px;
          background: transparent;
          border-radius: 50px;
          // border: none;
          // outline: none;
          text-indent: 12px;
          font-size: 0.8rem;
          // & 与input是同级样式
          &::-webkit-input-placeholder {
            font-size: 0.75rem;
            color: @cdd;
          }
        }
      }
    }
  }
  > main {
    flex: 1;
    height: calc(100% - 130px);
    // 当设置横向滚动为关闭的时候，不设置纵向，那么纵向就是自动滚动的
    overflow-x: hidden;
    // background: rgb(156, 121, 121);
    margin: 0 auto;
    // width: 410px;
    width: 80%;
    > ul {
      display: flex;
      justify-content: space-between;
      font-size: 0.8rem;
      width: 100%;

      justify-content: space-between;
    }
    > .van-swipe {
      display: block;
      width: 100%;
      height: 210px;
      margin: 0 auto 16px;
      border-radius: 4px;

      .van-swipe-item {
        width: 100%;
      }
    }
    > .type {
      display: flex;
      flex-wrap: wrap;
      div {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        width: 20%;
        height: 50%;
        font-size: 00.65rem;
      }
      img {
        width: 50px;
      }
    }
    > .hot {
      display: flex;
      justify-content: space-between;
      padding: 10px 8px;
      color: #fff;
      background: red;
      border-radius: 5px;
      margin: 10px;
      span {
        font-size: 1.3rem;
      }
      em {
        font-size: 1.1rem;
      }
    }
    > .recommend-list {
      margin-bottom: 10px;
      width: 100%;
      >img{
      width: 100%;
        
      }
      > .title {
        width: 240px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin-top: 12px;
        margin-bottom: 18px;
        margin-left: 20px;
      }
      > .price {
        margin-top: 20px;
        margin-bottom: 18px;
        margin-left: 20px;
        span {
          color: #877a73;
          margin-left: 20px;
          margin-right: 8px;
          font-size: 12px;

        }
        em {
          font-size: 12px;
          border: 1px solid red;
          width: 100px;
          height: 20px;
          line-height: 20px;
          text-align: center;
          color: red;
        }
      }
      > .platform {
        width: 240px;
        display: flex;
        justify-content: space-between;
        span {
          width: 40px;
          height: 20px;
          background: red;
          color: #fff;
          line-height: 20px;
          text-align: center;
          margin-left: 20px;
          margin-right: 8px;
        }
      }
    }
  }
}

footer {
  // display: block;
  // height: 49px;
  // border-top: solid 1px #eeeeee;
  // background: #fff;

  // > div {
  //   width: 25%;
  //   float: left;
  //   text-align: center;

  //   > img {
  //     //   display: block;
  //     height: 32px;
  //     vertical-align: top;
  //   }
  //   > span {
  //     display: block;
  //     height: 16px;
  //     //   text-align: center;
  //     font-size: 0.65rem;
  //     color: #545456;
  //   }
  // }
  // .clear();
  .footer{
       display:flex;
       justify-content: space-around;
  }
}
</style>




